/**
 * 20080124 1355: Eric Kao was created.
 */

package basic;

import info.Info;

import java.sql.Connection;
import java.sql.SQLException;

import pre.AbstractPreTable;
import pre.PreTestTable;

import com.e885.exception.E885DBException;
import com.e885.jdbc.JDBCUtil;
import com.e885.jdbc.OracleJDBC;

/**
 * 新增多筆資料, 並測試所花的時間和記憶體<br>
 * <br>
 * Copyright: Copyright (c) 2001-2008<br>
 * Company: E885 Group
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 */
public class QuantityInsertion
{
	private String ip = Info.IP;

	private int port = Info.PORT;

	private String userName = Info.USER_NAME;

	private String password = Info.PASSWORD;

	private String databaseName = Info.DATABASE_NAME;

	private Connection connection;

	public QuantityInsertion()
		throws E885DBException, SQLException
	{
		long startTime;
		long endTime;

		long memBefore;
		long memAfter;

		Runtime runtime = Runtime.getRuntime();

		JDBCUtil jdbcUtil = new OracleJDBC( ip, port, userName, password, databaseName );

		connection = jdbcUtil.getConnection();

		AbstractPreTable testTable = new PreTestTable( connection );

		testTable.createTable();
		
		memBefore = runtime.freeMemory();
		startTime = System.currentTimeMillis();

		testTable.insertData( 1000 );

		endTime = System.currentTimeMillis();
		memAfter = runtime.freeMemory();

		System.out.println( "Insert quantity data to use time: " + ( endTime - startTime ) + " ms" );
		System.out.println( "Insert quantity data to used memory: " + ( memBefore- memAfter ) + " bytes" );

		try
		{
			System.out.println( "It will drop table after 20 seconds." );

			Thread.sleep( 20 * 1000 );
		}
		catch( InterruptedException ex )
		{
		}

		testTable.dropTable();
	}

	public static void main( String[] args )
	{
		try
		{
			new QuantityInsertion();
		}
		catch( Exception ex )
		{
			ex.printStackTrace();
		}
	}
}
